package com.yanqu.road.dao.impl.log;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.LogEstateWine;

import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LogEstateWineDaoImpl extends TempDao {

	public boolean addLogEstateWineList(List<LogEstateWine> list) {
		getDb().setConnName(DbNameStrategy.getLogDb());
		String sql = "INSERT INTO t_l_estate_wine(userId,isGet,value,oldValue,nowValue,master,son,time) VALUES(?,?,?,?,?,?,?,?)";

		List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
		for (LogEstateWine data : list) {
			Map<Integer, DbParameter> para = new HashMap<>();
			int i = 1;
			para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
			para.put(i++, new DbParameter(Types.BOOLEAN, data.isGet()));
			para.put(i++, new DbParameter(Types.BIGINT, data.getValue()));
			para.put(i++, new DbParameter(Types.BIGINT, data.getOldValue()));
			para.put(i++, new DbParameter(Types.BIGINT, data.getNowValue()));
			para.put(i++, new DbParameter(Types.INTEGER, data.getMaster()));
			para.put(i++, new DbParameter(Types.INTEGER, data.getSon()));
			para.put(i++, new DbParameter(Types.TIMESTAMP, new Timestamp(data.getTime())));
			mapList.add(para);
		}

		return (getDb().executeBatchQuery(sql, mapList) > -1);
	}
}
